package com.hkts.management.unattended.poundroom.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import com.hkts.management.unattended.poundroom.service.IYbMutualPovouchService;
import com.hkts.management.unattended.utils.CustomPageUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.management.unattended.poundroom.service.IYbMutualSovouchService;
import com.hkts.management.unattended.poundroom.entity.YbMutualSovouch;

import java.util.List;
import java.util.Map;

/**
 * @author zy
 * @since 2021-10-13
 */
@RestController
@RequestMapping("/mutual/ybMutualSovouch")
public class YbMutualSovouchController {
    private final Logger logger = LoggerFactory.getLogger(YbMutualSovouchController.class);

    @Autowired
    public IYbMutualSovouchService iYbMutualSovouchService;

    @Autowired
    public IYbMutualPovouchService iYbMutualPovouchService;

    /**
     * 分页查询数据
     *
     * @param page            分页信息
     * @param ybMutualSovouch 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getYbMutualSovouchPageList")
    public Result<Object> getHontUserList(Page<YbMutualSovouch> page, YbMutualSovouch ybMutualSovouch) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iYbMutualSovouchService.selectPage(page, ybMutualSovouch)));
    }

    /**
     * 保存和修改公用的
     *
     * @param ybMutualSovouch 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybMutualSovouchSave")
    public Result<Object> ybMutualSovouchSave(YbMutualSovouch ybMutualSovouch) {
        iYbMutualSovouchService.saveOrUpdate(ybMutualSovouch);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/ybMutualSovouchGetById")
    public Result<Object> ybMutualSovouchGetById(String id) {
        YbMutualSovouch byId = iYbMutualSovouchService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybMutualSovouchDelete")
    public Result<Object> hontUserDelete(String id) {
        iYbMutualSovouchService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/ybMutualSovouchBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iYbMutualSovouchService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

    /**
     * 根据物料名称获取List<对象>
     *
     * @param name 物料名称
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/selectSovouchListBycInvName")
    public Result<Object> selectSovouchListBycInvName(Integer orderType,String name) {
        if (orderType == 1){
            List<Map<String,Object>> ybMutualSovouches = iYbMutualSovouchService.selectListByName(name);
            return ResultUtil.data(ybMutualSovouches);
        }else if(orderType == 2){
            List<Map<String,Object>> ybMutualPovouches = iYbMutualPovouchService.selectListByName(name);
            return ResultUtil.data(ybMutualPovouches);
        }else {
            return ResultUtil.data(null);
        }
    }

    /**
     * 根据code获取对象
     *
     * @param code 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/ybMutualSovouchGetBycSOCode/{code}")
    public Result<Object> ybMutualSovouchGetBycSOCode(@PathVariable(value="code")String code) {
        YbMutualSovouch byId = iYbMutualSovouchService.getBycSOCode(code);
        return ResultUtil.data(byId);
    }

}
